﻿using AbpBase.Application.Handlers.HandlerEvents;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Text;
using Volo.Abp.AspNetCore.Mvc;

namespace AbpBase.HttpApi.Controllers
{
    [ApiController]
    public class TestController : AbpController
    {
        private readonly ILogger _ILogger;
        public TestController(ILogger logger)
        {
            _ILogger = logger;
        }

        [HttpGet("/T")]
        public string MyWebApi()
        {
            _ILogger.Information("程序启动了");
            return "应用启动成功！";
        }

        public class TestModel
        {
            [Required]
            public int Id { get; set; }
            
            public int Iphone { get; set; }

            [Required]
            [MinLength(5)]
            public string Message { get; set; }
        }

        [HttpPost("/T2")]
        public string MyWebApi2([FromBody] TestModel model)
        {
            return "请求完成";
        }

        [HttpGet("/T3")]
        public string MyWebApi3()
        {
            int a = 1;
            int b = 0;
            int c = a / b;
            return c.ToString();
        }

        [HttpGet("/T4")]
        public string MyWebApi4()
        {
            try
            {
                int a = 1;
                int b = 0;
                int c = a / b;
            }
            catch (Exception ex)
            {
                new CustomerExceptionEvent(ex, MethodBase.GetCurrentMethod());
            }
            return "aaa";
        }
    }
}
